load("//bazel:tachyon.bzl", "if_gpu_is_configured")
load("//bazel:tachyon_cc.bzl", "tachyon_cc_library", "tachyon_cc_unittest")

package(default_visibility = ["//visibility:public"])

tachyon_cc_library(
    name = "poseidon2",
    hdrs = ["poseidon2.h"],
    deps = [
        ":poseidon2_config",
        ":poseidon2_horizen_external_matrix",
        ":poseidon2_horizen_internal_matrix",
        ":poseidon2_plonky3_external_matrix",
        ":poseidon2_plonky3_internal_matrix",
        ":poseidon2_vendor",
        "//tachyon/base/buffer:copyable",
        "//tachyon/crypto/hashes/sponge:sponge_state",
        "//tachyon/crypto/hashes/sponge/poseidon:poseidon_sponge_base",
        "//tachyon/math/finite_fields:finite_field_traits",
    ],
)

tachyon_cc_library(
    name = "poseidon2_config_entry",
    hdrs = ["poseidon2_config_entry.h"],
    deps = ["//tachyon/crypto/hashes/sponge/poseidon:poseidon_config_entry_base"],
)

tachyon_cc_library(
    name = "poseidon2_config",
    hdrs = ["poseidon2_config.h"],
    deps = [
        ":poseidon2_config_entry",
        "//tachyon/base/ranges:algorithm",
        "//tachyon/crypto/hashes/sponge/poseidon:poseidon_config_base",
        "//tachyon/math/finite_fields:finite_field_traits",
        "//tachyon/math/matrix:matrix_utils",
        "@com_google_absl//absl/types:span",
    ],
)

tachyon_cc_library(
    name = "poseidon2_external_matrix",
    hdrs = ["poseidon2_external_matrix.h"],
    deps = [
        ":poseidon2_external_matrix_traits_forward",
        "//tachyon/math/matrix:matrix_types",
        "//tachyon/math/matrix:matrix_utils",
    ],
)

tachyon_cc_library(
    name = "poseidon2_external_matrix_traits_forward",
    hdrs = ["poseidon2_external_matrix_traits_forward.h"],
)

tachyon_cc_library(
    name = "poseidon2_horizen_external_matrix",
    hdrs = ["poseidon2_horizen_external_matrix.h"],
    deps = [":poseidon2_external_matrix"],
)

tachyon_cc_library(
    name = "poseidon2_horizen_internal_matrix",
    hdrs = ["poseidon2_horizen_internal_matrix.h"],
    deps = ["//tachyon/math/matrix:matrix_types"],
)

tachyon_cc_library(
    name = "poseidon2_param_traits_forward",
    hdrs = ["poseidon2_param_traits_forward.h"],
)

tachyon_cc_library(
    name = "poseidon2_params",
    hdrs = ["poseidon2_params.h"],
    deps = [
        ":poseidon2_vendor",
        "//tachyon/base/types:always_false",
        "//tachyon/math/finite_fields:finite_field_traits",
    ],
)

tachyon_cc_library(
    name = "poseidon2_plonky3_external_matrix",
    hdrs = ["poseidon2_plonky3_external_matrix.h"],
    deps = [":poseidon2_external_matrix"],
)

tachyon_cc_library(
    name = "poseidon2_plonky3_internal_matrix",
    hdrs = ["poseidon2_plonky3_internal_matrix.h"],
    deps = [
        ":poseidon2_horizen_internal_matrix",
        "//tachyon/base:logging",
        "//tachyon/math/finite_fields:finite_field_traits",
        "//tachyon/math/matrix:matrix_types",
    ],
)

tachyon_cc_library(
    name = "poseidon2_vendor",
    hdrs = ["poseidon2_vendor.h"],
    deps = [
        "//tachyon:export",
        "//tachyon/base:logging",
    ],
)

tachyon_cc_unittest(
    name = "poseidon2_unittests",
    srcs = [
        "poseidon2_external_matrix_unittest.cc",
        "poseidon2_internal_matrix_unittest.cc",
        "poseidon2_unittest.cc",
    ],
    deps = [
        ":poseidon2",
        ":poseidon2_params",
        "//tachyon/base/buffer:vector_buffer",
        "//tachyon/crypto/hashes/sponge/poseidon2/param_traits:poseidon2_baby_bear",
        "//tachyon/crypto/hashes/sponge/poseidon2/param_traits:poseidon2_goldilocks",
        "//tachyon/math/finite_fields/mersenne31",
        "//tachyon/math/finite_fields/test:finite_field_test",
    ],
)

tachyon_cc_unittest(
    name = "poseidon2_gpu_unittests",
    srcs = if_gpu_is_configured(["poseidon2_gpu_unittest.cc"]),
    deps = [
        ":poseidon2",
        ":poseidon2_params",
        "//tachyon/crypto/hashes/sponge/poseidon2/icicle:icicle_poseidon2_holder",
        "//tachyon/crypto/hashes/sponge/poseidon2/param_traits:poseidon2_baby_bear",
        "//tachyon/crypto/hashes/sponge/poseidon2/param_traits:poseidon2_bn254",
        "//tachyon/math/finite_fields/test:finite_field_test",
    ],
)
